float updatePID(float setPoint, float processVariable, float dt, struct pidData *PID) {
  /* PID Pseudocode from:  http://en.wikipedia.org/wiki/PID_controller
  error = setpoint - actual_position
  integral = integral + error*dt
  derivative = (error - previous_error)/dt
  output = Kp*error + Ki*integral + Kd*derivative
  previous_error = error */
  float error, derivative;
 
  error = setPoint - processVariable;
  PID->integral += error * dt;
  if (PID->integral < -PID->windupGuard) PID->integral = -PID->windupGuard;
  else if (PID->integral > PID->windupGuard) PID->integral = PID->windupGuard;
  derivative = (processVariable - PID->previousPV) / dt;
  PID->previousPV = processVariable;
  return (PID->Kp * error) + (PID->Ki * PID->integral) + (PID->Kd * derivative);
}
  
